package fem2;

import math2.ConstantFunctionRnToR;
import math2.FunctionRnToR;

/**
 * A fasten class for gravity load. <br>
 * In 3d, gravity load point ro - z-direction<br>
 * in 2d, load point to - y-direction
 * 
 * @author hbui
 * 
 */
public class GravityLoad extends Load {

	public final static double g = -9.81;

	private Load load;

	/**
	 * 
	 * @param mp
	 *            mesh part
	 * @param density
	 *            density by a unit volume. If mesh part is a block, density if
	 *            weight over unit volume. In case mesh part is a face, density
	 *            is weight over unit area. If mesh is edge, density is weight
	 *            over unit length
	 */
	public GravityLoad(MeshPart mp, double density) {
		super(mp);
		FunctionRnToR f = new ConstantFunctionRnToR(density * g);
		int dim = mp.getDimension();
		if (dim == 2) {
			load = new DistributedLoad(mp, null, f);
		} else if (dim == 3) {
			load = new DistributedLoad(mp, null, null, f);
		} else {
			throw new Error("invalid dimension");
		}
	}

	@Override
	public double[] computeRe(double t) {
		return load.computeRe(t);
	}

	@Override
	public void setTimeFactor(FunctionRnToR lambda) {
		load.setTimeFactor(lambda);
	}

}
